package com.designpattern.behavior.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Administration
 * @date 2021/10/26 - 14:25 - 星期二
 * @project 行为型模式中得 观察者模式  具体主题（具体被观察者）
 * @package com.designpattern.behavior.observer
 * @by 晨
 */
public class SubscriptionSubject implements Subject{

    private List<Observer> weixinUserlist = new ArrayList<>();

    @Override
    public void attach(Observer observer) {
        weixinUserlist.add(observer);
    }

    @Override
    public void detach(Observer observer) {
        weixinUserlist.remove(observer);
    }


    @Override
    public void notify(String message) {
        weixinUserlist.forEach((x) -> {
            x.update(message);
        });
    }
}
